﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public static class EnumerableExtensions
{
    /// <summary>
    /// Performs the specified action on each element of the collection
    /// </summary>
    /// <typeparam name="T">type of the collection</typeparam>
    /// <param name="items">collections</param>
    /// <param name="action">The Action<T> delegate to perform on each element of the colletion.</param>
    public static void ForEach<T>(this IEnumerable<T> items, Action<T> action)
    {
        foreach (var item in items)
        {
            action(item);
        }
    }

    /// <summary>
    /// Concatenates the members of a collection, using the specified separator
    /// between each member.
    /// </summary>
    /// <param name="source">A collection that contains the objects to concatenate</param>
    /// <param name="separator">The string to use as a separator.</param>
    /// <returns>A string that consists of the members of values delimited by the separator string.</returns>
    public static string Join(this IEnumerable<object> source, string separator)
    {
        return source.Join<object>(separator);
    }

    /// <summary>
    /// Concatenates the members of a collection, using the specified separator
    /// between each member.
    /// </summary>
    /// <typeparam name="T">The type of the members of values</typeparam>
    /// <param name="source">A collection that contains the objects to concatenate</param>
    /// <param name="separator">The string to use as a separator.</param>
    /// <returns>A string that consists of the members of values delimited by the separator string.</returns>
    public static string Join<T>(this IEnumerable<T> source, string separator)
    {
        return String.Join<T>(separator, source);
    }
}
